<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:r="clr-namespace:Org.Dna.Aurora.UIFramework.Wpf.Timeline.TreeListViewControl"
    xmlns:s="clr-namespace:System;assembly=mscorlib">

  <r:LevelToIndentConverter x:Key="LevelToIndentConverter"/>

  <Style TargetType="{x:Type r:TreeListViewItem}">

    <Setter Property="Panel.Background">
      <Setter.Value>
        <SolidColorBrush>#00FFFFFF</SolidColorBrush>
      </Setter.Value>
    </Setter>
    <Setter Property="Control.VerticalContentAlignment">
      <Setter.Value>
        <x:Static Member="VerticalAlignment.Center" />
      </Setter.Value>
    </Setter>
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate TargetType="r:TreeListViewItem">
          <StackPanel>
            <Border BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Bd" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True" Padding="{TemplateBinding Control.Padding}">
              <r:TreeGridViewRowPresenter x:Name="PART_Header"
                FirstColumnIndent="{Binding Level,Converter={StaticResource LevelToIndentConverter},RelativeSource={RelativeSource AncestorType={x:Type r:TreeListViewItem}},ConverterParameter=19}"
                Content="{TemplateBinding Header}" 
                Columns="{Binding Path=Columns,RelativeSource={RelativeSource AncestorType={x:Type r:TreeListView}}}">
                <r:TreeGridViewRowPresenter.Expander>
                  <Grid>
                    <ToggleButton Height="19" Width="19" ClickMode="Press" Name="Expander" IsChecked="{Binding Path=IsExpanded,RelativeSource={RelativeSource AncestorType={x:Type r:TreeListViewItem}}}">
                      <ToggleButton.Style>
                        <Style TargetType="ToggleButton">
                          <Style.Resources>
                            <ResourceDictionary />
                          </Style.Resources>
                          <Setter Property="UIElement.Focusable">
                            <Setter.Value>
                              <s:Boolean>False</s:Boolean>
                            </Setter.Value>
                          </Setter>
                          <Setter Property="FrameworkElement.Width">
                            <Setter.Value>
                              <s:Double>19</s:Double>
                            </Setter.Value>
                          </Setter>
                          <Setter Property="FrameworkElement.Height">
                            <Setter.Value>
                              <s:Double>13</s:Double>
                            </Setter.Value>
                          </Setter>
                          <Setter Property="Control.Template">
                            <Setter.Value>
                              <ControlTemplate TargetType="ToggleButton">
                                <Border Height="13" Width="19" Background="#00FFFFFF">
                                  <Border Height="9" BorderBrush="#FF7898B5" CornerRadius="1,1,1,1" Width="9" BorderThickness="1,1,1,1" SnapsToDevicePixels="True">
                                    <Border.Background>
                                      <LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
                                        <LinearGradientBrush.GradientStops>
                                          <GradientStop Offset="0.2" Color="#FFFFFFFF" />
                                          <GradientStop Offset="1" Color="#FFC0B7A6" />
                                        </LinearGradientBrush.GradientStops>
                                      </LinearGradientBrush>
                                    </Border.Background>
                                    <Path Margin="1,1,1,1" Data="M0,2L0,3 2,3 2,5 3,5 3,3 5,3 5,2 3,2 3,0 2,0 2,2z" Fill="#FF000000" Name="ExpandPath" />
                                  </Border>
                                </Border>
                                <ControlTemplate.Triggers>
                                  <Trigger Property="ToggleButton.IsChecked">
                                    <Setter Property="Path.Data" TargetName="ExpandPath">
                                      <Setter.Value>
                                        <StreamGeometry>M0,2L0,3 5,3 5,2z</StreamGeometry>
                                      </Setter.Value>
                                    </Setter>
                                    <Trigger.Value>
                                      <s:Boolean>True</s:Boolean>
                                    </Trigger.Value>
                                  </Trigger>
                                </ControlTemplate.Triggers>
                              </ControlTemplate>
                            </Setter.Value>
                          </Setter>
                        </Style>
                      </ToggleButton.Style>
                    </ToggleButton>
                  </Grid>
                </r:TreeGridViewRowPresenter.Expander>
              </r:TreeGridViewRowPresenter>
            </Border>

            <ItemsPresenter Name="ItemsHost" />
          </StackPanel>
          <ControlTemplate.Triggers>
            <Trigger Property="TreeViewItem.IsExpanded">
              <Setter Property="UIElement.Visibility" TargetName="ItemsHost" Value="{x:Static Visibility.Collapsed}" />
              <Trigger.Value>
                <s:Boolean>False</s:Boolean>
              </Trigger.Value>
            </Trigger>
            <Trigger Property="ItemsControl.HasItems">
              <Setter Property="UIElement.Visibility" TargetName="Expander" Value="{x:Static Visibility.Hidden}" />
              <Trigger.Value>
                <s:Boolean>False</s:Boolean>
              </Trigger.Value>
            </Trigger>

            <Trigger Property="TreeViewItem.IsSelected">
              <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
              <Setter Property="TextElement.Foreground" TargetName="Bd">
                <Setter.Value>
                  <DynamicResource ResourceKey="{x:Static SystemColors.HighlightTextBrushKey}" />
                </Setter.Value>
              </Setter>
              <Trigger.Value>
                <s:Boolean>True</s:Boolean>
              </Trigger.Value>
            </Trigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="TreeViewItem.IsSelected">
                  <Condition.Value>
                    <s:Boolean>True</s:Boolean>
                  </Condition.Value>
                </Condition>
                <Condition Property="TreeViewItem.IsSelectionActive">
                  <Condition.Value>
                    <s:Boolean>False</s:Boolean>
                  </Condition.Value>
                </Condition>
              </MultiTrigger.Conditions>
              <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
              <Setter Property="TextElement.Foreground" TargetName="Bd">
                <Setter.Value>
                  <DynamicResource ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" />
                </Setter.Value>
              </Setter>
            </MultiTrigger>
            <Trigger Property="UIElement.IsEnabled">
              <Setter Property="TextElement.Foreground" TargetName="Bd">
                <Setter.Value>
                  <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                </Setter.Value>
              </Setter>
              <Trigger.Value>
                <s:Boolean>False</s:Boolean>
              </Trigger.Value>
            </Trigger>
          </ControlTemplate.Triggers>

        </ControlTemplate>
      </Setter.Value>
    </Setter>

  </Style>

  <Style x:Key="scroll">
    <Setter Property="UIElement.Focusable">
      <Setter.Value>
        <s:Boolean>False</s:Boolean>
      </Setter.Value>
    </Setter>
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ScrollViewer}">
          <Grid Background="{TemplateBinding Background}"
                SnapsToDevicePixels="true">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
              <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="*"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <DockPanel Margin="{TemplateBinding Padding}">
              <ScrollViewer DockPanel.Dock="Top"
                            HorizontalScrollBarVisibility="Hidden"
                            VerticalScrollBarVisibility="Hidden"
                            Focusable="false">
                <GridViewHeaderRowPresenter Columns="{Binding Path=Columns,RelativeSource={RelativeSource AncestorType={x:Type r:TreeListView}}}"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
              </ScrollViewer>
              <ScrollContentPresenter Name="PART_ScrollContentPresenter"
                                      KeyboardNavigation.DirectionalNavigation="Local"
                                      Content="{TemplateBinding Content}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                      CanContentScroll="{TemplateBinding CanContentScroll}"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
            </DockPanel>
            <ScrollBar Name="PART_HorizontalScrollBar"
                       Orientation="Horizontal"
                       Grid.Row="1"
                       Minimum="0.0"
                       Maximum="{TemplateBinding ScrollableWidth}"
                       ViewportSize="{TemplateBinding ViewportWidth}"
                       Value="{Binding Path=HorizontalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                       Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                       Cursor="Arrow"/>
            <ScrollBar Name="PART_VerticalScrollBar"
                       Orientation="Vertical"
                       Grid.Column="1"
                       Minimum="0.0"
                       Maximum="{TemplateBinding ScrollableHeight}"
                       ViewportSize="{TemplateBinding ViewportHeight}"
                       Value="{Binding Path=VerticalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                       Cursor="Arrow"/>
            <DockPanel Grid.Column="1"
                       Grid.Row="1"
                       Background="{Binding Path=Background,ElementName=PART_VerticalScrollBar}"
                       LastChildFill="false">
              <Rectangle DockPanel.Dock="Left"
                         Width="1"
                         Fill="White"
                         Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
              <Rectangle DockPanel.Dock="Top"
                         Height="1"
                         Fill="White"
                         Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
            </DockPanel>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type r:TreeListView}">

    <Setter Property="Panel.Background">
      <Setter.Value>
        <DynamicResource ResourceKey="{x:Static SystemColors.WindowBrushKey}" />
      </Setter.Value>
    </Setter>
    <Setter Property="Border.BorderBrush">
      <Setter.Value>
        <SolidColorBrush>#FF7F9DB9</SolidColorBrush>
      </Setter.Value>
    </Setter>
    <Setter Property="Border.BorderThickness">
      <Setter.Value>
        <Thickness>1,1,1,1</Thickness>
      </Setter.Value>
    </Setter>
    <Setter Property="TextElement.Foreground">
      <Setter.Value>
        <DynamicResource ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" />
      </Setter.Value>
    </Setter>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility">
      <Setter.Value>
        <x:Static Member="ScrollBarVisibility.Auto" />
      </Setter.Value>
    </Setter>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility">
      <Setter.Value>
        <x:Static Member="ScrollBarVisibility.Auto" />
      </Setter.Value>
    </Setter>
    <Setter Property="ScrollViewer.CanContentScroll">
      <Setter.Value>
        <s:Boolean>True</s:Boolean>
      </Setter.Value>
    </Setter>
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate TargetType="r:TreeListView">
          <Border BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Bd" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
            <ScrollViewer Style="{StaticResource scroll}" Background="{TemplateBinding Background}"
              Focusable="false"
              CanContentScroll="false"
              HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
              VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
              Padding="{TemplateBinding Padding}"
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
              <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
            </ScrollViewer>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="ItemsControl.IsGrouping">
              <Setter Property="ScrollViewer.CanContentScroll">
                <Setter.Value>
                  <s:Boolean>False</s:Boolean>
                </Setter.Value>
              </Setter>
              <Trigger.Value>
                <s:Boolean>True</s:Boolean>
              </Trigger.Value>
            </Trigger>
            <Trigger Property="UIElement.IsEnabled">
              <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
              <Trigger.Value>
                <s:Boolean>False</s:Boolean>
              </Trigger.Value>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>